# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: Arch Haskell Team <arch-haskell@haskell.org>

pkgname=pandoc-crossref
pkgver=0.3.16.0
pkgrel=67
pkgdesc="Pandoc filter for cross-references"
url="https://hackage.haskell.org/package/${pkgname}"
license=("GPL2")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-data-default' 'haskell-gitrev' 'haskell-microlens'
         'haskell-microlens-ghc' 'haskell-microlens-mtl' 'haskell-microlens-th' 'haskell-open-browser'
         'haskell-optparse-applicative' 'haskell-pandoc' 'haskell-pandoc-types' 'haskell-syb'
         'haskell-utility-ht')
makedepends=('ghc' 'haskell-hspec' 'pandoc-cli')
conflicts=('haskell-pandoc-crossref')
replaces=('haskell-pandoc-crossref')
source=("https://hackage.haskell.org/packages/archive/${pkgname}/${pkgver}/${pkgname}-${pkgver}.tar.gz")
sha512sums=('e3033fb5aa5f78026340dda28ff14396188a9ebc9de1fa7d3d9b5ede7aa601b38f104082ffeb5c7da30f4c57b3c3909f399a4e8fff62d0a776929ddb71922e48')

build() {
  cd $pkgname-$pkgver
  runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
    --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
    --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm \
    -f-enable_flaky_tests
  runhaskell Setup build $MAKEFLAGS
  runhaskell Setup register --gen-script
  runhaskell Setup unregister --gen-script
  sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
  sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
  cd $pkgname-$pkgver
  runhaskell Setup test --show-details=direct
}

package() {
  cd $pkgname-$pkgver

  install -D -m744 register.sh   "${pkgdir}/usr/share/haskell/register/${pkgname}.sh"
  install -D -m744 unregister.sh "${pkgdir}/usr/share/haskell/unregister/${pkgname}.sh"
  runhaskell Setup copy --destdir="${pkgdir}"
  rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
